<template>
  <div>
    <button @click="increment">+1</button>
    <button @click="decrement">-1</button>
    <button @click="incrementN">+n</button>
    <input type="text" v-model.number="num" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      num: 0,
    };
  },
  // emits: ["add", "sub", "addN"],
  emits: {
    add: null,
    sub: null,
    addN: (num) => {
      if (num > 10) {
        return true;
      }
      return false;
    },
  },
  methods: {
    increment() {
      this.$emit("add");
    },
    decrement() {
      this.$emit("sub");
    },
    incrementN() {
      console.log("子组件", this.num);
      this.$emit("addN", this.num);
    },
  },
};
</script>

<style scoped></style>
